package com.ebs.md.api.comparators;

/**
 * Revision Author:
 *  $File: //depot/MarketData/commons-md-api/MAIN/src/main/java/com/ebs/md/api/comparators/DetailedBookEntryComparator.java $
 *  $Revision: #1 $
 *  $DateTime: 2012/04/29 09:26:44 $
 *  $Change: 110636 $
 *  $Author: Arik.Sher $
 */

import java.util.Comparator;

import com.ebs.md.api.IDetailedBookEntry;

public class DetailedBookEntryComparator
implements Comparator<IDetailedBookEntry>
{
	protected static final BasicBookEntryComparator basicComp = new BasicBookEntryComparator();
	
	/**
	 * compare order:
	 * 1) rate
	 * 2) quoteTime (earlier quotes should be appear first)
	 * 3) quoteId   (didn't know what to compare else, and don't want to return 0)
	 * 
	 * make sure this function won't return 0, so entries won't disapper, if rate and time equal
	 */
	public int compare(IDetailedBookEntry be1, IDetailedBookEntry be2) {
		int compVal = basicComp.compare(be1, be2);
		
		if ( compVal == 0 ) {
			compVal = 	be1.getQuoteTime().compareTo(
						be2.getQuoteTime()
			);
		}
		
		if ( compVal == 0 ) {
			// handling case when rate and time are equal.
			// for now comparing the quote ids. 
			compVal = 	be1.getQuoteId().compareTo(
						be2.getQuoteId()
			);
		}
		
		return compVal;
	}

}
